<template>
  <info :id="id" type="used_car" title="二手车" :loadDataMethod="loadData"></info>
</template>

<script>
import Info from '@c/page/Info'
export default {
  components: {
    Info
  },

  data (){
    return {
      id: ''
    }
  },

  beforeMount (){
    this.id = this.$route.query.id
  },

  methods: {
    // 加载数据
    loadData (){
      return new Promise((resolve, reject) =>{
        _api('usedCar/getById', {
          level: '0,2,5',
          id: this.id
        }).then(data =>{
          var {user, car_manuf, tel, is_collect} = data

          var imgs = data.img.split(',')
          var infoCard = {
            avatar: user.avatar,
            userName: user.nick_name,
            rightText: data.price === '0.00' ? '面议' : data.price + '万' ,
            isTransfer: data.is_transfer,
            info: [
              {
                title: '车辆品牌',
                value: car_manuf.name,
                showy: true
              }, {
                title: '上牌时间',
                value: data.license_at.replace(/^(\d{4})-(\d\d)-(\d\d)$/, (s, s1, s2, s3) =>
                  `${s1}年${s2.replace(/^0/, '')}月${s3.replace(/^0/, '')}日`
                )
              }, {
                title: '所属公司',
                value: data.company || '无'
              }, {
                title: '备注',
                value: data.remark || '这个人很懒，什么都没有写'
              }
            ]
          }

          resolve({ imgs, tel, infoCard, collected: !!parseInt(is_collect) })
        }).catch(reject)
      })
    },
  }
}
</script>

<style lang="less" scoped>

</style>